# Copyright 2004 Hirotaka Ogawa, hirotaka.ogawa@gmail.com
# This software is provided as-is. You may use it for commercial or 
# personal use. If you distribute it, please keep this notice intact.

use strict;
use MT::Template::Context;

if (MT->can('add_plugin')) {
    require MT::Plugin;
    my $plugin = new MT::Plugin();
    $plugin->name("SetVarBlock Plugin, v.0.01");
    $plugin->description("Add SetVarBlock container tag.");
    $plugin->doc_link("http://as-is.net/blog/archives/000917.html");
    MT->add_plugin($plugin);
}

MT::Template::Context->add_container_tag('SetVarBlock' => sub {
    my ($ctx, $args) = @_;
    my $builder = $ctx->stash('builder');
    my $tokens = $ctx->stash('tokens');
    defined(my $text = $builder->build($ctx, $tokens))
	or return $ctx->error($builder->errstr);
    $ctx->{__stash}{vars}{$args->{name}} = $text;
    ''
});
